package com.zr.service.base.impl;

import java.util.*;
import com.zr.utils.Md5Util;
import javax.annotation.Resource;
import com.zr.vo.base.BaseDriver;
import com.zr.dao.base.BaseDriverDao;
import org.springframework.util.StringUtils;
import com.zr.service.base.BaseDriverService;
import org.springframework.stereotype.Service;

/**
 * 司机增删改查实现类
 */
@Service
public class BaseDriverServiceImpl implements BaseDriverService {
    @Resource
    private BaseDriverDao baseDriverDao;

    /**
     * 条件查询司机信息列表
     * @param baseDriver
     * @return
     * @author liutienan
     */
    @Override
    public List<BaseDriver> list(BaseDriver baseDriver) {

        return baseDriverDao.selectByConditions(baseDriver);
    }

    /**
     * 查询所有司机信息
     * @return
     * @author liutienan
     */
    @Override
    public List<BaseDriver> listAll() {
        return baseDriverDao.listAll();
    }

    /**
     * 新增司机信息
     * @param baseDriver
     * @return
     * @author liutienan
     */
    @Override
    public int add(BaseDriver baseDriver) {
        baseDriver.setPassword(Md5Util.md5(baseDriver.getPassword()));
        baseDriver.setCreateTime(new Date());
        return baseDriverDao.insertSelective(baseDriver);
    }

    /**
     * 修改司机信息
     * @param baseDriver
     * @return
     * @author liutienan
     */
    @Override
    public int edit(BaseDriver baseDriver) {
        if(StringUtils.hasLength(baseDriver.getPassword())){
            baseDriver.setPassword(Md5Util.md5(baseDriver.getPassword()));
        }else {
            baseDriver.setPassword(null);
        }
        baseDriver.setModifyTime(new Date());
        return baseDriverDao.updateByPrimaryKeySelective(baseDriver);
    }

    /**
     * 删除司机信息
     * @param id
     * @return
     * @author liutienan
     */
    @Override
    public int remove(Integer id) {
        return baseDriverDao.deleteByPrimaryKey(id);
    }


}
